<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <!-- 主表 -->
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('分配批次')" prop="distributionPeriod">
            <el-input v-model="form.distributionPeriod" :placeholder="$t('分配批次')" show-word-limit maxlength="32" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('分配日期')" prop="distributionDate">
            <DatePicker v-model="form.distributionDate" :placeholder="$t('分配日期')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('收益主体')" prop="incomeSubject">
            <el-select v-model="form.incomeSubject" :placeholder="$t('收益主体')" @change="setIncomeSubjectName(form.incomeSubject)">
              <el-option
                v-for="investment in incomeSubjects"
                :key="investment.id"
                :label="investment.investorName"
                :value="investment.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('分配类型')" prop="distributionType">
            <el-select v-model="form.distributionType" value="" :placeholder="$t('分配类型')">
              <el-option
                v-for="item in dictDistributionType"
                :key="item.id"
                :label="item.dictLabel"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('分配本金') + $t('金额单位')" prop="distributionPrincipal">
            <Money v-model="form.distributionPrincipal" unit="w" :placeholder="$t('分配本金')" @change="calcAmount" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('分配收益') + $t('金额单位')" prop="distributionIncome">
            <Money v-model="form.distributionIncome" unit="w" :placeholder="$t('分配收益')" @change="calcAmount" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('分配金额') + $t('金额单位')" prop="distributionAmount">
            <Money v-model="form.distributionAmount" unit="w" :placeholder="$t('分配金额')" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('币种')">
            <el-select v-model="form.currency" value="" :placeholder="$t('币种')">
              <!--              <el-option :label="$t('请选择字典生成')" value="" />-->
              <el-option
                v-for="item in dictCurrency"
                :key="item.id"
                :label="item.dictLabel"
                :value="item.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('回收资金原因')" prop="reasonsForFundRecovery">
            <el-input
              v-model="form.reasonsForFundRecovery"
              type="textarea"
              :placeholder="$t('回收资金原因')"
              show-word-limit
              maxlength="1000"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('收益原因')" prop="earningsReason">
            <el-input
              v-model="form.earningsReason"
              type="textarea"
              :placeholder="$t('收益原因')"
              show-word-limit
              maxlength="1000"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('分配原因')" prop="assignmentReason">
            <el-input
              v-model="form.assignmentReason"
              type="textarea"
              :placeholder="$t('分配原因')"
              show-word-limit
              maxlength="1000"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="note">
            <el-input v-model="form.note" type="textarea" :placeholder="$t('备注')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 股权项目分配信息 -->
      <div style="margin-top:15px;">
        <div class="area-header">
          <span class="area-header-title">{{ $t('股权项目分配信息') }}</span>
        </div>
        <div>
          <el-table
            v-loading="fymxLoading"
            :data="form.dealArray"
            border
            class="nowrapTable formTable"
          >
            <el-table-column :label="$t('序号')" align="center" width="50">
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('项目名称')" align="center">
              <template slot="header" slot-scope="{}">
                <i style="color: #ff4949;margin-right: 4px;">*</i>
                <span>{{ $t('项目名称') }}</span>
              </template>
              <template slot-scope="scope">
                <el-form-item :prop="'dealArray.' + scope.$index + '.projectName'" :rules="dealInfoCheck.projectName">
                  <el-select v-model="scope.row.projectName" filterable :placeholder="$t('项目名称')" @change="getAccumulatedAmountByProject(scope.$index)">
                    <el-option
                      v-for="item in getDealList"
                      :key="item.id"
                      :label="$t(item.company.companyName)"
                      :value="item.id"
                    />
                  </el-select>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('分配本金') + $t('金额单位')" align="center">
              <template slot-scope="scope">
                <el-form-item :prop="'dealArray.' + scope.$index + '.distributionPrincipal'" :rules="dealInfoCheck.distributionPrincipal">
                  <Money v-model="scope.row.distributionPrincipal" unit="w" :placeholder="$t('')" @change="moneySum(scope.$index,1)" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('分配收益') + $t('金额单位')" align="center" @change="moneySum(scope.$index,1)">
              <template slot-scope="scope">
                <el-form-item :prop="'dealArray.' + scope.$index + '.distributionIncome'" :rules="dealInfoCheck.distributionIncome">
                  <Money v-model="scope.row.distributionIncome" unit="w" :placeholder="$t('')" @change="moneySum(scope.$index,1)" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('分配金额') + $t('金额单位')" align="center">
              <template slot-scope="scope">
                <el-form-item prop="incomeAmount">
                  <Money v-model="scope.row.incomeAmount" unit="w" :placeholder="$t('')" disabled />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('累计分配金额') + $t('金额单位')" align="center">
              <template slot-scope="scope">
                <el-form-item prop="cumulativeDistributionAmount">
                  <Money v-model="scope.row.cumulativeDistributionAmount" unit="w" :placeholder="$t('')" disabled />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('备注')" align="center">
              <template slot-scope="scope">
                <el-form-item prop="note">
                  <el-input v-model="scope.row.note" type="textarea" maxlength="200" class="fileTextarea" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column v-if="!dealArrayHide" :label="$t('操作')" align="center" width="60px">
              <template slot-scope="scope">
                <el-button size="small" type="text" icon="el-icon-delete" @click="delDealInfo(scope.$index, scope.row)" />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="tol">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="addDealInfo">{{ $t("添加") }}</el-button>
        </div>
      </div>
      <!-- 基金项目分配信息 -->
      <div style="margin-top:15px;">
        <div class="area-header">
          <span class="area-header-title">{{ $t('基金项目分配信息') }}</span>
        </div>
        <div>
          <el-table
            v-loading="fymxLoading"
            :data="form.fundArray"
            border
            class="nowrapTable formTable"
          >
            <el-table-column :label="$t('序号')" align="center" width="50">
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('基金名称')" align="center">
              <template slot="header" slot-scope="{}">
                <i style="color: #ff4949;margin-right: 4px;">*</i>
                <span>{{ $t('基金名称') }}</span>
              </template>
              <template slot-scope="scope">
                <el-form-item :prop="'fundArray.' + scope.$index + '.projectName'" :rules="dealInfoCheck.projectName">
                  <el-select v-model="scope.row.projectName" filterable :placeholder="$t('基金名称')" @change="getAccumulatedAmountByProject(scope.$index)">
                    <el-option
                      v-for="item in getFundList"
                      :key="item.id"
                      :label="$t(item.fundName)"
                      :value="item.id"
                    />
                  </el-select>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('分配本金') + $t('金额单位')" align="center">
              <template slot-scope="scope">
                <el-form-item :prop="'fundArray.' + scope.$index + '.distributionPrincipal'" :rules="dealInfoCheck.distributionPrincipal">
                  <Money v-model="scope.row.distributionPrincipal" unit="w" :placeholder="$t('')" @change="moneySum(scope.$index,2)" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('分配收益') + $t('金额单位')" align="center" @change="moneySum(scope.$index,2)">
              <template slot-scope="scope">
                <el-form-item :prop="'fundArray.' + scope.$index + '.distributionIncome'" :rules="dealInfoCheck.distributionIncome">
                  <Money v-model="scope.row.distributionIncome" unit="w" :placeholder="$t('')" @change="moneySum(scope.$index,2)" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('分配金额') + $t('金额单位')" align="center">
              <template slot-scope="scope">
                <el-form-item prop="incomeAmount">
                  <Money v-model="scope.row.incomeAmount" unit="w" :placeholder="$t('')" disabled />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('累计分配金额') + $t('金额单位')" align="center">
              <template slot-scope="scope">
                <el-form-item prop="cumulativeDistributionAmount">
                  <Money v-model="scope.row.cumulativeDistributionAmount" unit="w" :placeholder="$t('')" disabled />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('备注')" align="center">
              <template slot-scope="scope">
                <el-form-item prop="note">
                  <el-input v-model="scope.row.note" type="textarea" maxlength="200" class="fileTextarea" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column v-if="!fundArrayHide" :label="$t('操作')" align="center" width="60px">
              <template slot-scope="scope">
                <el-button size="small" type="text" icon="el-icon-delete" @click="delFundInfo(scope.$index, scope.row)" />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="tol">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="addFundInfo">{{ $t("添加") }}</el-button>
        </div>
      </div>
      <!-- 非项目分配信息 -->
      <div style="margin-top:15px;">
        <div class="area-header">
          <span class="area-header-title">{{ $t('非项目分配信息') }}</span>
        </div>
        <div>
          <el-table
            v-loading="fymxLoading"
            :data="form.otherArray"
            border
            class="nowrapTable formTable"
          >
            <el-table-column :label="$t('序号')" align="center" width="50">
              <template slot-scope="scope">
                {{ scope.$index + 1 }}
              </template>
            </el-table-column>
            <el-table-column :label="$t('分配类型')" align="center">
              <template slot="header" slot-scope="{}">
                <i style="color: #ff4949;margin-right: 4px;">*</i>
                <span>{{ $t('分配类型') }}</span>
              </template>
              <template slot-scope="scope">
                <el-form-item :prop="'otherArray.' + scope.$index + '.distributionType'" :rules="dealInfoCheck.distributionType">
                  <el-select v-model="scope.row.distributionType" value="" :placeholder="$t('分配类型')">
                    <el-option
                      v-for="item in dictDistributionType"
                      :key="item.id"
                      :label="item.dictLabel"
                      :value="item.id"
                    />
                  </el-select>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('分配本金') + $t('金额单位')" align="center">
              <template slot-scope="scope">
                <el-form-item prop="distributionPrincipal">
                  <Money v-model="scope.row.distributionPrincipal" unit="w" :placeholder="$t('')" @change="moneySum(scope.$index,3)" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('分配收益') + $t('金额单位')" align="center">
              <template slot-scope="scope">
                <el-form-item prop="distributionIncome">
                  <Money v-model="scope.row.distributionIncome" unit="w" :placeholder="$t('')" @change="moneySum(scope.$index,3)" />
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column :label="$t('分配金额') + $t('金额单位')" align="center">
              <template slot-scope="scope">
                <el-form-item prop="incomeAmount">
                  <Money v-model="scope.row.incomeAmount" unit="w" :placeholder="$t('')" disabled />
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column :label="$t('备注')" align="center">
              <template slot-scope="scope">
                <el-form-item prop="note">
                  <el-input v-model="scope.row.note" type="textarea" maxlength="200" class="fileTextarea" />
                </el-form-item>
              </template>
            </el-table-column>

            <el-table-column v-if="!dealArrayHide" :label="$t('操作')" align="center" width="60px">
              <template slot-scope="scope">
                <el-button size="small" type="text" icon="el-icon-delete" @click="delOtherInfo(scope.$index, scope.row)" />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="tol">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="addOtherInfo">{{ $t("添加") }}</el-button>
        </div>
      </div>

    </el-form>
    <!--按钮-->
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="bf:bfDistribution" />
    </div>
  </div>
</template>

<script>
import {
  saveDealBfDistribution,
  getDealBfDistribution,
  getAccumulatedAmount
} from '@/api/deal/bf/distribution/dealBfDistribution'
import { listBfInvestGroupNoPage } from '@/api/bf/investGroup/bfInvestGroup.js'
import { listBfInvestFundNoPage } from '@/api/bf/investGroup/bfInvestFund.js'
import { delDealBfDistributionDeal } from '@/api/deal/bf/distribution/dealBfDistributionDeal.js'
import { delDealBfDistributionOther } from '@/api/deal/bf/distribution/dealBfDistributionOther.js'
import { listDealInvestment } from '@/api/deal/investment/dealInvestment'

export default {
  data() {
    return {
      // 表单参数
      form: {
        // 基金分配
        distributionAmount: 0,
        distributionPrincipal: 0,
        distributionIncome: 0,
        dealId: this.$route.query.id,
        dealArray: [],
        fundArray: [],
        otherArray: []
      },
      dealId: this.$route.query.id,
      // 遮罩层
      loading: false,
      dealArrayHide: false,
      fundArrayHide: false,
      otherArrayHide: false,
      fymxLoading: false,
      dealInfoCheck: {
        projectName: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        distributionType: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        distributionPrincipal: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }],
        distributionIncome: [{ required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }]
      },
      // 分配类型
      dictDistributionType: [],
      // 币种信息
      dictCurrency: [],
      // 收益主体
      incomeSubjects: [],
      // 获取项目信息
      getDealList: [],
      // 获取基金项目
      getFundList: [],
      // 表单校验
      rules: {
        distributionPeriod: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ], distributionDate: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ], incomeSubject: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ], distributionType: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ], distributionAmount: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    // 项目信息
    this.project()
    // 字典
    this.dictAll()
    // 收益主体
    this.getlistDealInvestment()
    this.$bus.$emit('async_done')
  },
  methods: {
    // 初始化数据
    init(data) {
      console.log('data-shuju', data)
      if (data != null && data.id !== undefined) {
        getDealBfDistribution(data.id).then(response => {
          this.form = response.data
          this.form.dealId = this.$route.query.id
          // 初始化分配金额
          const deal = this.form.dealArray
          const fund = this.form.fundArray
          const other = this.form.otherArray
          deal.forEach(item => {
            item.distributionPrincipal = parseInt(item.distributionPrincipal)
            item.distributionIncome = parseInt(item.distributionIncome)
            item.incomeAmount = item.distributionPrincipal + item.distributionIncome
          })
          fund.forEach(item => {
            item.distributionPrincipal = parseInt(item.distributionPrincipal)
            item.distributionIncome = parseInt(item.distributionIncome)
            item.incomeAmount = item.distributionPrincipal + item.distributionIncome
          })
          other.forEach(item => {
            item.distributionPrincipal = parseInt(item.distributionPrincipal)
            item.distributionIncome = parseInt(item.distributionIncome)
            item.incomeAmount = item.distributionPrincipal + item.distributionIncome
          })
        })
      } else {
        this.reset()
      }
    },
    // 设置收益主体名称，用于同步项目最新事件
    setIncomeSubjectName(value) {
      this.incomeSubjects.forEach(item => {
        if (item.id === value) {
          this.form.incomeSubjectName = item.investorName
        }
      })
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealId: this.$route.query.id,
        distributionPeriod: undefined,
        distributionDate: undefined,
        incomeSubject: undefined,
        distributionType: undefined,
        distributionAmount: undefined,
        distributionPrincipal: undefined,
        distributionIncome: undefined,
        currency: 'CNY',
        reasonsForFundRecovery: undefined,
        earningsReason: undefined,
        assignmentReason: undefined,
        note: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        dealArray: [],
        fundArray: [],
        otherArray: []
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      this.$parent.$parent.reset()
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      this.$parent.$parent.formOpen = false
      // 刷新list页面
      this.$parent.$parent.getList()
    },
    // 提交按钮
    submitForm: function() {
      console.log(this.form)
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          saveDealBfDistribution(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('保存成功'))
              this.closeForm()
            } else {
              this.msgError(response.msg)
            }
            this.loading = false
          })
        } else {
          this.locationError(document)
        }
      })
    },
    // 添加项目信息
    addDealInfo() {
      const row = {
        id: undefined,
        projectName: undefined,
        note: '',
        dealId: this.$route.query.id,
        distributionPrincipal: 0,
        incomeAmount: 0,
        distributionIncome: 0,
        cumulativeDistributionAmount: 0
      }
      if (!(this.form.dealArray instanceof Array)) {
        this.$set(this.form, 'dealArray', [])
      }
      this.$nextTick(() => {
        this.form.dealArray.push(row)
      })
    },
    // 删除项目信息
    delDealInfo(index, row) {
      const id = row.id
      if (id !== undefined && id !== '' && id != null) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(function() {
          return delDealBfDistributionDeal(id)
        }).then(() => {
          this.form.dealArray.splice(index, 1)
          // this.calculationMoney()
          return this.msgSuccess(this.$t('删除成功'))
        })
            .catch(function() {
            })
      } else {
        this.form.dealArray.splice(index, 1)
        // this.calculationMoney()
      }
    },
    // 添加基金项目信息
    addFundInfo() {
      const row = {
        id: undefined,
        projectName: undefined,
        note: '',
        dealId: this.$route.query.id,
        distributionPrincipal: 0,
        incomeAmount: 0,
        distributionIncome: 0,
        cumulativeDistributionAmount: 0
      }
      if (!(this.form.fundArray instanceof Array)) {
        this.$set(this.form, 'fundArray', [])
      }
      this.$nextTick(() => {
        this.form.fundArray.push(row)
      })
    },
    // 删除项目信息
    delFundInfo(index, row) {
      const id = row.id
      if (id !== undefined && id !== '' && id != null) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(function() {
          return delDealBfDistributionDeal(id)
        }).then(() => {
          this.form.fundArray.splice(index, 1)
          // this.calculationMoney()
          return this.msgSuccess(this.$t('删除成功'))
        })
          .catch(function() {
          })
      } else {
        this.form.fundArray.splice(index, 1)
        // this.calculationMoney()
      }
    },
    // 添加非项目信息
    addOtherInfo() {
      const row = {
        id: undefined,
        projectName: undefined,
        note: '',
        dealId: this.$route.query.id,
        distributionPrincipal: 0,
        incomeAmount: 0,
        distributionIncome: 0,
        cumulativeDistributionAmount: 0
      }
      if (!(this.form.otherArray instanceof Array)) {
        this.$set(this.form, 'otherArray', [])
      }
      this.$nextTick(() => {
        this.form.otherArray.push(row)
      })
    },
    // 删除非项目信息
    delOtherInfo(index, row) {
      const id = row.id
      if (id !== undefined && id !== '' && id != null) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(function() {
          return delDealBfDistributionOther(id)
        }).then(() => {
          console.log(this.form.otherArray)
          this.form.otherArray.splice(index, 1)
          // this.calculationMoney()
          return this.msgSuccess(this.$t('删除成功'))
        })
            .catch(function() {
            })
      } else {
        this.form.otherArray.splice(index, 1)
        // this.calculationMoney()
      }
    },
    // tpye： 1 项目 2 基金 2 非项目
    moneySum(index, type) {
      // this.form.distributionAmount = 0
      // this.form.distributionPrincipal = 0
      // this.form.distributionIncome = 0
      const deal = this.form.dealArray
      const fund = this.form.fundArray
      const other = this.form.otherArray
      if (type === 1) {
        deal[index].incomeAmount = deal[index].distributionPrincipal + deal[index].distributionIncome
      } else if (type === 2) {
        fund[index].incomeAmount = fund[index].distributionPrincipal + fund[index].distributionIncome
      } else if (type === 3) {
        other[index].incomeAmount = other[index].distributionPrincipal + other[index].distributionIncome
      }
      // this.calculationMoney()
    },
    // 计算 总本金 总收益 总金额
    calculationMoney() {
      const form = this.form
      const deal = this.form.dealArray
      const fund = this.form.fundArray
      const other = this.form.otherArray
      if ((deal === undefined || deal.length === 0) && (fund === undefined || fund.length === 0) && (other === undefined || deal.length === 0)) {
        this.form.distributionAmount = 0
        this.form.distributionPrincipal = 0
        this.form.distributionIncome = 0
      }
      deal.forEach(item => {
        form.distributionPrincipal += item.distributionPrincipal
        form.distributionAmount += item.incomeAmount
        form.distributionIncome += item.distributionIncome
      })
      fund.forEach(item => {
        form.distributionPrincipal += item.distributionPrincipal
        form.distributionAmount += item.incomeAmount
        form.distributionIncome += item.distributionIncome
      })
      other.forEach(item => {
        form.distributionPrincipal += item.distributionPrincipal
        form.distributionAmount += item.incomeAmount
        form.distributionIncome += item.distributionIncome
      })
    },
    // 计算主表分配金额
    calcAmount() {
        var distributionPrincipal = this.form.distributionPrincipal ? Number(this.form.distributionPrincipal) : 0
        var distributionIncome = this.form.distributionIncome ? Number(this.form.distributionIncome) : 0
        this.form.distributionAmount = distributionPrincipal + distributionIncome
    },
    // 获取累计金额
    getAccumulatedAmountByProject(index) {
      const deal = this.form.dealArray[index]
      if (deal.projectName !== undefined) {
        getAccumulatedAmount(deal.projectName).then(response => {
          if (response.data === undefined) {
            deal.cumulativeDistributionAmount = 0
          } else {
            deal.cumulativeDistributionAmount = response.data
          }
        })
      }
      const fund = this.form.fundArray[index]
      if (fund.projectName !== undefined) {
        getAccumulatedAmount(fund.projectName).then(response => {
          if (response.data === undefined) {
            fund.cumulativeDistributionAmount = 0
          } else {
            fund.cumulativeDistributionAmount = response.data
          }
        })
      }
    },
    // 收益主体
    getlistDealInvestment() {
      this.incomeSubjects = undefined
      listDealInvestment({ 'dealId': this.form.dealId }).then(response => {
        this.incomeSubjects = response.rows
      })
    },
    dictAll() {
      this.getDicts('distribution_type').then(response => {
        this.dictDistributionType = response.data
      })
      this.getDicts('currency').then(response => {
        this.dictCurrency = response.data
      })
    },
    project() {
      listBfInvestGroupNoPage({ 'dealId': this.$route.query.id }).then(response => {
        console.log(response.data)
        this.getDealList = response.data
      })
      listBfInvestFundNoPage({ 'dealId': this.$route.query.id }).then(response => {
        console.log(response.rows)
        this.getFundList = response.rows
      })
    }
  }
}
</script>
